package com.gesee.zyspps.widgets;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class CustomCircleView extends View
{
    Paint paint;    
    private final Context context;  

    public CustomCircleView(Context context) {    

        this(context, null);     
    }    
    
    public CustomCircleView(Context context, AttributeSet attrs) {  
        super(context, attrs);  
        // TODO Auto-generated constructor stub  
        this.context = context;  
        this.paint = new Paint();  
        this.paint.setAntiAlias(true); //消除锯齿  
        this.paint.setStyle(Paint.Style.STROKE); //绘制空心圆   
    }  

      /**
       * 
      * @Title: onDraw
      * @Description: TODO(绘制图形方法 )
      * @author fujianxiong
      * @param canvas
      * @throws
       */
    @Override    
    protected void onDraw(Canvas canvas) {    
        int center = getWidth()/2;  
        int innerCircle = dip2px(context, 83); //设置内圆半径  
        int ringWidth = dip2px(context, 5); //设置圆环宽度  
          
        //绘制内圆  
        this.paint.setARGB(155, 167, 190, 206);  
        this.paint.setStrokeWidth(2);  
        canvas.drawCircle(center,center, innerCircle, this.paint);  
          
        //绘制圆环  
        this.paint.setARGB(255, 212 ,225, 233);  
        this.paint.setStrokeWidth(ringWidth);  
        canvas.drawCircle(center,center, innerCircle+1+ringWidth/2, this.paint);  
          
        //绘制外圆  
        this.paint.setARGB(155, 167, 190, 206);  
        this.paint.setStrokeWidth(2);  
        canvas.drawCircle(center,center, innerCircle+ringWidth, this.paint);  
  
          
        super.onDraw(canvas);   
    }    
    
    /**
     * 
    * @Title: dip2px
    * @Description: TODO(根据手机的分辨率从 dp 的单位 转成为 px(像素) )
    * @author fujianxiong
    * @param context
    * @param dpValue
    * @return
    * @throws
     */
    public static int dip2px(Context context, float dpValue) {  
        final float scale = context.getResources().getDisplayMetrics().density;  
        return (int) (dpValue * scale + 0.5f);  
    }  
}
